extends layout
block content
  h1=apiInfo.name
  .apiName(id=apiName)
  script.
    count = 0;
  - if (apiInfo.auth && apiInfo.auth.oauth && apiInfo.auth.oauth.version && apiInfo.auth.oauth.version == "1.0" && apiInfo.auth.oauth.type =='three-legged')
      - var oAuthVersion = '1.0'
      - if (session.authed)
        - var authed = 'authed'
  - else if (apiInfo.auth && apiInfo.auth.oauth && apiInfo.auth.oauth.version && apiInfo.auth.oauth.version == "2.0")
      - var oAuthVersion = '2.0'
      - if (session.authed)
        - var authed = 'authed'
  - else
      - var authed =''

  form#credentials
      input(type='hidden', name='apiName', value=apiName)
      - if (apiInfo.auth)
          section(class='credentials ' + authed)
              - if (oAuthVersion == '1.0')
                  input(type='hidden', name='oauth', value='authrequired')
              - else if (oAuthVersion == '2.0')
                  input(type='hidden', name='oauth2', value='authrequired')

              - if (apiInfo.auth.defaultKey)
                  - var defaultKey =apiInfo.auth.defaultKey
              - else
                  - var defaultKey =''

              - if (apiInfo.auth.defaultSecret)
                  - var defaultSecret =apiInfo.auth.defaultSecret
              - else
                  - var defaultSecret =''
              div
                  - if (oAuthVersion)
                      label(for='key') Client ID
                      - var secure ='authrequired'
                      input(id='key', name='key', value=defaultKey, style='color=#EEEEEE')
                  - else if (apiInfo.auth == 'basicAuth')
                    label(for='username') User name
                    input(id='username', name='username', value=defaultKey, style='color=#EEEEEE')
                  - else
                    label(for='key') API Key
                    - var secure =''
                    input(id='key', name='key', value=defaultKey, style='color=#EEEEEE')
              div
                  - if (oAuthVersion)
                      label(for='secret') Client Secret
                      input(id='secret', name='secret', value=defaultSecret, style='color=#EEEEEE')
                  - else if (apiInfo.auth == 'basicAuth')
                      label(for='password') Password
                      input(id='password', name='password', type='password', value=defaultKey, style='color=#EEEEEE')

                  - if (apiInfo.auth.signature)
                      label(for='secret') Shared Secret
                      input(id='secret', name='secret', value=defaultSecret, style='color=#EEEEEE')
              - if (oAuthVersion == '1.0' && apiInfo.auth.oauth.type !='two-legged')
                  div
                     input(name='oauth', value='Authenticate with OAuth', type='submit', id='oauth-auth')
              - else if (oAuthVersion == '2.0')
                  div
                     input(name='oauth', value='Authenticate with OAuth2', type='submit', id='oauth-auth')
              div(id='oauthAuthenticated', style='display:none')
                  br
                  span(style='vertical-align:botttom') Authenticated with OAuth
                      img(src='images/accept.png')
              - if (authed && oAuthVersion)
                  script.
                      document.getElementById('oauthAuthenticated').style.display = 'block';


  div(id='controls')
      ul
          li
              a#toggle-resources(href='#') Toggle All Resources
          li
              a#toggle-methods(href='#') Toggle All Methods

  ul
      - each resource, resourceName in apiInfo.resources
          li.resource
              h3.title
                  span.name
                      a(href='#'+resourceName.replace(/\s/g, '-'))!=resourceName
                  ul.actions
                      li.list-methods
                          a(href='#') List Methods
                      li.expand-methods
                          a(href='#') Expand Methods
              - if (Object.keys(resource).length)
              ul.methods.hidden
                  - each method, methodKey in resource.methods
                      div(id = method.httpMethod)
                      - var httpmethod = method.httpMethod.toLowerCase()
                      li(class='method ' + httpmethod + ' ' + secure)
                          div.title.clickable
                              - var methodLink = (resourceName + '-' + method.httpMethod + '-' + method.name).replace(/\s/g, '-')
                              div(id = methodLink)
                              a(href='#'+methodLink)
                              span.http-method !{method.httpMethod}
                              span.name !{method.name}
                              span.uri !{method.path}
                          form.hidden(class='container')
                              input(type='hidden', name='httpMethod', value=method.httpMethod)
                              input(type='hidden', name='oauth', value=secure)
                              input(type='hidden', name='methodUri', value=method.path)
                              input(type='hidden', name='accessToken', id='accessToken')
                              input(type='hidden', name='json', id=methodKey + 'json')
                              input(type='hidden', name='locations', id=methodKey + 'locations')

                              span.description !{method.description}
                              br
                              br
                              .container.header
                                .row
                                  .col-description.header Description !{method.MethodName}
                                  .location.header Location
                                  .col-type.header Type
                                  .col-parameter.header Value
                                  .col-name.header Parameter
                              table(id=methodKey)
                              - if (!method['read-only'])
                                  input(type='submit', id=method.name, value='Try it!', class=methodKey)